package com.red.wood.module.redis.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.red.wood.common.util.CommonUtils;
import com.red.wood.module.redis.service.PersonPortraitService;

import net.sf.json.JSONObject;

@RestController
@RequestMapping("/personportraitAPI")
public class PersonPortraitController {

	private static final Log log = LogFactory.getLog(PersonPortraitController.class);
	
	@Autowired
    private PersonPortraitService service;
	
	@PostMapping(value = "/ga.newTrajectoryDetail")
	public String newTrajectoryDetail(HttpServletRequest request, HttpServletResponse response) {
		JSONObject json = new JSONObject();
		try {
			String msisdn = CommonUtils.valueOf(request.getParameter("msisdn"));
			json.put("status","1");
			json.put("msg","success");
			json.put("data",service.getPersonDetail(msisdn));
		}catch(Exception e) {
			if(log.isErrorEnabled()) {
				log.error(e.getMessage(),e);
			}
			json.put("status","0");
			json.put("msg","fail");
			json.put("data", new JSONObject());
		}	
		return json.toString();
	}
}
